import { Buffer } from 'buffer';
import scrypt from 'scrypt-js';

export async function createPassword(password: string): Promise<string> {
  const saltBuffer = Buffer.from(
    import.meta.env.VITE_PASSWORD_SECRET as string,
    'utf8'
  );
  const passwordBuffer = Buffer.from(password, 'utf8');
  const scryptPassword = await scrypt.scrypt(
    passwordBuffer,
    saltBuffer,
    1024,
    16,
    8,
    32
  );
  return Buffer.from(scryptPassword).toString('hex');
}
